package com.users.rn.rncommon.router;

import android.content.Context;

import com.users.rn.rncommon.model.SchemeModule;
import com.users.rn.rncommon.util.ReactUtils;

import java.util.ArrayList;

/**
 * @Description:
 * @Author: bluce
 * @Date: 2020/12/3 11:10
 */
public class RNRouterManager {
    private static final ArrayList<RNRouterInterface> routerImpl = new ArrayList<>();

    public synchronized static void open(Context context, SchemeModule model) {
        for (RNRouterInterface routerInter : routerImpl) {
            if (routerInter.isOperator(model)) {
                routerInter.operator(context, model);
                return;
            }
        }
        //默认处理
        ReactUtils.openRnPageView(context, model);
    }

    /**
     * 注册rn路由
     *
     * @param rnRouterInterface
     */
    public static void register(RNRouterInterface rnRouterInterface) {
        if (rnRouterInterface == null) {
            return;
        }
        routerImpl.add(rnRouterInterface);
    }
}
